package com.shenfa.dao;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.shenfa.bean.City;
import com.shenfa.bean.PaperCityCrd;

/**
 * 外包商作业分配数据库操作类
 * 
 * @author yanglong
 * 
 * @date 2011-8-22
 *
 */
public class EpibCityDao {
	
	@Autowired
	private SqlMapClient sqlMapClient;
	
	/**
	 * 根据外包商作业分配对象条件查询作业分配列表
	 * @param t		作业分配
	 * @param start	开始索引
	 * @param limit	每页大小
	 * @return	作业分配列表
	 */
	@SuppressWarnings("unchecked")
	public List<PaperCityCrd> getList(PaperCityCrd t, int start, int limit) {
		List<PaperCityCrd> list = null;
		try {
			list = sqlMapClient.queryForList("epibcity_manager.getList",t,start,limit);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
	public int getCount(PaperCityCrd t) {
		int a;
		try {
			a = (Integer)sqlMapClient.queryForObject("epibcity_manager.getCount",t);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		return a;
	}

	/**
	 * 添加外包商作业分配信息
	 * @param t	作业分配
	 * @return	1成功，0失败
	 */
	public int add(PaperCityCrd t) {
		try {
			sqlMapClient.insert("epibcity_manager.add", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}

	/**
	 * 删除外包商作业分配信息
	 * @param t	作业分配
	 * @return	1成功，0失败
	 */
	public int del(PaperCityCrd t) {
		try {
			sqlMapClient.delete("epibcity_manager.del", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	/**
	 * 更新外包商作业分配信息
	 * @param t	作业分配
	 * @return	1成功，0失败
	 */
	public int upd(PaperCityCrd t) {
		try {
			sqlMapClient.update("epibcity_manager.upd", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	/**
	 * 根据对象条件查询卡产品指定外包商发布城市编号
	 */
	@SuppressWarnings("unchecked")
	public List<String> getNoList(PaperCityCrd t) {
		try {
			return sqlMapClient.queryForList("epibcity_manager.getIdList", t);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 指定预印纸发布城市编号
	 */
	@SuppressWarnings("unchecked")
	public List<String> getNoList1(PaperCityCrd t) {
		try {
			return sqlMapClient.queryForList("epibcity_manager.getCitynoByPaperno", t);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 外包商可选发布城市列表
	 */
	@SuppressWarnings("unchecked")
	public List<City> getAllList(PaperCityCrd t) {
		try {
			return sqlMapClient.queryForList("epibcity_manager.getAllList", t);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public List<City> getSheng(List<City> list){
		try {
			return sqlMapClient.queryForList("epibcity_manager.getSheng",list);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/**
	 * 预印纸可选发布城市列表
	 */
	@SuppressWarnings("unchecked")
	public List<City> getAllList1(PaperCityCrd t) {
		try {
			return sqlMapClient.queryForList("epibcity_manager.getListCityByCardno", t);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 将指定卡产品指定外包商对应城市设为空
	 * @return 1成功，0失败
	 */
	public int updNull(PaperCityCrd t) {
		try {
			sqlMapClient.update("epibcity_manager.updNull", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}

}
